<script>
  // 1、已知persons用户信息数据：
  let persons = [
    { username: "xiaoming1", password: "1111" },
    { username: "xiaoming2", password: "222" },
    { username: "xiaoming3", password: "33333" },
  ];
  // 2、现有
  let user = { username: "admin1", password: "12345" }; 
  //注册原理：如果persons中没有对应的用户，则把user追加到persons末尾
  if (persons.find((item) => item.username == user.username)) {
    document.write("该用户已注册");
  } else {
    persons=[...persons,user];
    // persons.push(...user);
    document.write("注册成功");
  }
  console.log(persons); 
  //登录原理：如果persons中含有对应的用户名和密码则提示登录成功，否则提示用户名和密码错误
  if (persons.some((item) => item.username == user.username)) {
    if (
      persons.find((item) => item.username == user.username).password ==
      user.password
    ) {
      document.write("登陆成功");
    } else {
      document.write("用户密码错误");
    }
  } else {
    document.write("该用户不存在");
  }
</script>
